﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for UserData
/// </summary>
public class UserData
{
	public UserData()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public bool add(UsersEntities item)
    {
        bool flat = false;
        string[] pamamaters = { "@username", "@password", "@name", "@email", "@messenger", "@mobile", "@role_id", "@position", "@birthday", "@address", "@gender", "@display", "@status" };
        string[] values = {item._userName,item._pass,item._name,item._email,item._messenger,item._mobile,item._roleID.ToString(),item._position,item._birthday,item._address,item._gender,item._display,item._status };
        if (Database.getExecProcedure("InsertUser", pamamaters, values) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }

    public bool register(UsersEntities item)
    {
        bool flat = false;
        string[] pamamaters = { "@username", "@password", "@name", "@email", "@messenger", "@mobile", "@birthday", "@address", "@gender"};
        string[] values = { item._userName, item._pass, item._name, item._email, item._messenger, item._mobile, item._birthday, item._address, item._gender };
        if (Database.getExecProcedure("Register", pamamaters, values) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }
    public bool editU_P(UsersEntities item)
    {
        bool flat = false;
        string[] pamamaters = { "@id", "@username", "@password" };
        string[] values = {item._userID.ToString(), item._userName, item._pass};
        if (Database.getExecProcedure("EditUserName", pamamaters, values) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }
    public bool edit(UsersEntities item)
    {
        bool flat = false;
        string[] pamamaters = {"@id", "@name", "@email", "@messenger", "@mobile", "@role_id", "@position", "@birthday", "@address", "@gender", "@display", "@status" };
        string[] values = {item._userID.ToString(), item._name, item._email, item._messenger, item._mobile, item._roleID.ToString(), item._position, item._birthday, item._address, item._gender, item._display, item._status };
        if (Database.getExecProcedure("EditUser", pamamaters, values) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }
    public bool delete(int id)
    {
        bool flat = false;
        string[] pamamaters = { "@id" };
        string[] values = { id.ToString()};
        if (Database.getExecProcedure("DeleteUser", pamamaters, values) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }
    public DataTable getUser(int id)
    {
        return Database.getTable("exec GetUser '"+id.ToString()+"'");
    }

    public System.Data.SqlClient.SqlDataReader login(string username, string password)
    {
        string[] paramater = { "@username", "@password" };
        string[] values = { username, password };
        return Database.getReaderProcedure("UserLogin", paramater, values);
    }
    public System.Data.SqlClient.SqlDataReader GetUserView()
    {
        return Database.getReader("exec getUserView");
    }
}
